<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

function buildForm($formElements)
{
	$CI =& get_instance();
	$html = '';
	foreach ($formElements as $el) {
		$html .= '<p class="form-'.$el['name'].'">'."\n";

		$elHtml = '';
		switch ($el['type']) {
			case 'text':
				$elHtml .=  form_input($el);
			break;
			case 'submit':
				$elHtml .=  form_input($el);
			break;
			case 'password':
				$elHtml .=  form_password($el);
			break;
			case 'textarea':
				$elHtml .=  form_textarea($el);
			break;
			case 'checkbox':
				$elHtml .=  form_checkbox($el);
			break;
			case 'radio':
				$elHtml .=  form_radio($el);
			break;
			case 'select':
				$elHtml .=  form_dropdown($el['name'], $el['options'], $CI->input->post($el['name'],TRUE), $el['class']);
			break;
			case 'submit':
				$elHtml .=  form_submit($el);
			break;
			case 'button':
				$elHtml .= form_button($el); 
			break;
		}
		
		if($el['name']!='submit')
		{
			$html .= form_label(ucfirst(str_replace('_', ' ', $el['name'])), $el['name']).' '.$elHtml."\n";
		} else {
			$html .= $elHtml;
		}
		
		$html .= "\n".'</p>'."\n";
	}
 
	return $html;
}